<?php

require_once 'table.php';

class Citizen {
	var $id;
	var $name;
	var $tag;
	var $level;
	var $strength;
	var $rank;
	var $work;
	var $avatar;
	var $dead;
	
	var $rank_name;
	var $rank_percent;
	var $influ;

  function Citizen($id,$name,$tag,$level,$strength,$rank,$work,$avatar,$dead)
  {
		$this->id = $id;
		$this->name = $name;
		$this->tag = $tag;
		$this->level = $level;
		$this->strength = $strength;
		$this->rank = $rank;
		$this->work = $work;
		$this->avatar = $avatar;
		$this->dead = $dead;
	}

	function Process()
	{
		$detail = getRank($this->rank);
		
		$this->influ = (($detail[0]-1)/20 + 0.3) * (($this->strength / 10) + 40);
		$this->rank_name = $detail[1];
		$this->rank_percent = $detail[2];
	}

	function Output()
	{
		$str = $this->id . ","
		 . $this->name . ","
		 . $this->tag . ","
		 . $this->level . ","
		 . $this->strength . ","
		 . $this->rank . ","
		 . $this->work . ","
		 . $this->avatar . ",";
		 
		if ($this->dead == TRUE) {
			$str .= "1\n";
		} else {
			$str .= "0\n";
		}
		
		return $str;
	}

	/* This is the static comparing function: */
	static function cmp_influ($a, $b)
	{
		$al = $a->influ;
		$bl = $b->influ;
		if ($a->dead == TRUE && $b->dead == FALSE) {
			return +1;
		} else if ($a->dead == FALSE && $b->dead == TRUE) {
			return -1;
		} else if ($al == $bl) {
			return 0;
		}
		return ($al < $bl) ? +1 : -1;
	}

	static function cmp_strength($a, $b)
	{
		$al = $a->strength;
		$bl = $b->strength;
		if ($a->dead == TRUE && $b->dead == FALSE) {
			return +1;
		} else if ($a->dead == FALSE && $b->dead == TRUE) {
			return -1;
		} else if ($al == $bl) {
			return 0;
		}
		return ($al < $bl) ? +1 : -1;
	}

	static function cmp_rank($a, $b)
	{
		$al = $a->rank;
		$bl = $b->rank;
		if ($a->dead == TRUE && $b->dead == FALSE) {
			return +1;
		} else if ($a->dead == FALSE && $b->dead == TRUE) {
			return -1;
		} else if ($al == $bl) {
			return 0;
		}
		return ($al < $bl) ? +1 : -1;
	}

	static function cmp_work($a, $b)
	{
		$al = $a->work;
		$bl = $b->work;
		if ($a->dead == TRUE && $b->dead == FALSE) {
			return +1;
		} else if ($a->dead == FALSE && $b->dead == TRUE) {
			return -1;
		} else if ($al == $bl) {
			return 0;
		}
		return ($al < $bl) ? +1 : -1;
	}

	static function cmp_name($a, $b)
	{
		$al = strtolower($a->name);
		$bl = strtolower($b->name);
		if ($a->dead == TRUE && $b->dead == FALSE) {
			return +1;
		} else if ($a->dead == FALSE && $b->dead == TRUE) {
			return -1;
		} else if ($al == $bl) {
			return 0;
		}
		return ($al > $bl) ? +1 : -1;
	}

	static function cmp_tag($a, $b)
	{
		$al = intval(substr($a->tag,1));
		$bl = intval(substr($b->tag,1));
		if ($al == $bl) {
			return 0;
		}
		return ($al > $bl) ? +1 : -1;
	}

}

?>